/*
 * Copyright 2012-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.context.properties.source;

/**
 * 用于指示 {@link ConfigurationPropertySource} 是否支持
 * {@link ConfigurationPropertyCaching} 的接口。
 *
 * @author Phillip Webb
 */
interface CachingConfigurationPropertySource {

	/**
	 * 返回该来源的 {@link ConfigurationPropertyCaching}。
	 * @return 配置属性来源的缓存控制器
	 */
	ConfigurationPropertyCaching getCaching();

	/**
	 * 查找指定配置属性来源的 {@link ConfigurationPropertyCaching}。
	 * @param source 配置属性来源
	 * @return {@link ConfigurationPropertyCaching} 实例；如果该来源不支持缓存则返回 {@code null}
	 */
	static ConfigurationPropertyCaching find(ConfigurationPropertySource source) {
		if (source instanceof CachingConfigurationPropertySource) {
			return ((CachingConfigurationPropertySource) source).getCaching();
		}
		return null;
	}

}
